package com.cxh.mchat.common.entity;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.cxh.mchat.common.utils.DateUtil;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

/**
 * @author cxh
 * @date 2021/12/23 16:45
 **/
@Data
public abstract class BaseEntity<ID extends Serializable> implements Serializable {

    private static final long serialVersionUID = 1L;

    protected Long id;

    private String status;

    protected Integer optimistic;

    @TableField(value = "create_time",fill = FieldFill.INSERT)
    protected Date createTime;

    @TableField(value = "last_update_time",fill = FieldFill.INSERT_UPDATE)
    protected Date lastUpdateTime;

    @TableField(exist = false)
    private String createTimeFormat;

    public String getCreateTimeFormat() {
        if(null != createTime){
            return DateUtil.formatChineseTime(createTime);
        }
        return createTimeFormat;
    }

    @TableField(exist = false)
    private String lastUpdateTimeFormat;

    public String getLastUpdateTimeFormat() {
        if(null != lastUpdateTime){
            return DateUtil.formatChineseTime(lastUpdateTime);
        }
        return lastUpdateTimeFormat;
    }
}